package p270jp.pxv.android.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.material.textview.MaterialTextView;
import p018ai.C0218e;
import p270jp.pxv.android.R;
import p350mp.Timber;

/* renamed from: jp.pxv.android.view.SegmentedLayout */
/* loaded from: classes2.dex */
public class SegmentedLayout extends FrameLayout implements View.OnClickListener {

    /* renamed from: c */
    public OnSelectSegmentListener f19684c;

    /* renamed from: d */
    public int f19685d;

    /* renamed from: e */
    public boolean f19686e;

    /* renamed from: h */
    public final Drawable f19689h;

    /* renamed from: i */
    public final int f19690i;

    /* renamed from: j */
    public final int f19691j;

    /* renamed from: b */
    public int f19683b = -1;

    /* renamed from: f */
    public int f19687f = getResources().getDimensionPixelSize(R.dimen.segmented_layout_item_top_bottom_padding);

    /* renamed from: g */
    public int f19688g = getResources().getDimensionPixelSize(R.dimen.segmented_layout_item_left_right_padding);

    /* renamed from: a */
    public LinearLayout f19682a = new LinearLayout(getContext());

    /* renamed from: jp.pxv.android.view.SegmentedLayout$OnSelectSegmentListener */
    /* loaded from: classes2.dex */
    public interface OnSelectSegmentListener {
        void onSegmentSelected(int i);
    }

    public SegmentedLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0, 2131887300);
        this.f19685d = 14;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C0218e.f750h, 0, 2131887300);
        this.f19685d = obtainStyledAttributes.getDimensionPixelSize(4, this.f19685d);
        this.f19686e = obtainStyledAttributes.getBoolean(0, this.f19686e);
        this.f19689h = obtainStyledAttributes.getDrawable(2);
        this.f19690i = obtainStyledAttributes.getColor(1, 0);
        this.f19691j = obtainStyledAttributes.getColor(3, 0);
        obtainStyledAttributes.recycle();
        this.f19682a.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        this.f19682a.setOrientation(0);
        this.f19682a.setGravity(17);
        addView(this.f19682a);
    }

    /* renamed from: a */
    public void m4467a(String[] strArr, int i) {
        boolean z = this.f19682a.getChildCount() == 0;
        for (String str : strArr) {
            FrameLayout frameLayout = new FrameLayout(getContext());
            frameLayout.setOnClickListener(this);
            if (this.f19686e) {
                frameLayout.setLayoutParams(new LinearLayout.LayoutParams(0, -1, 1.0f));
            } else {
                frameLayout.setLayoutParams(new LinearLayout.LayoutParams(-2, -1));
            }
            MaterialTextView materialTextView = new MaterialTextView(getContext(), null);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
            layoutParams.gravity = 17;
            materialTextView.setLayoutParams(layoutParams);
            int i2 = this.f19688g;
            int i3 = this.f19687f;
            materialTextView.setPadding(i2, i3, i2, i3);
            materialTextView.setTextSize(0, (float) this.f19685d);
            materialTextView.setSingleLine();
            materialTextView.setText(str);
            materialTextView.setGravity(17);
            m4466b(materialTextView, this.f19682a.getChildCount() == 0);
            frameLayout.addView(materialTextView);
            this.f19682a.addView(frameLayout);
        }
        if (z) {
            setSelectedSegment(i);
        }
    }

    /* renamed from: b */
    public final void m4466b(TextView textView, boolean z) {
        if (z) {
            textView.setTextColor(this.f19691j);
            textView.setBackground(this.f19689h);
            textView.setTypeface(null, 1);
            return;
        }
        textView.setTextColor(this.f19690i);
        textView.setBackgroundResource(0);
        textView.setTypeface(null, 0);
    }

    public int getCurrentSelectedIndex() {
        return this.f19683b;
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View view) {
        for (int i = 0; i < this.f19682a.getChildCount(); i++) {
            if (view == this.f19682a.getChildAt(i)) {
                setSelectedSegment(i);
                return;
            }
        }
    }

    public void setOnSelectSegmentListener(OnSelectSegmentListener onSelectSegmentListener) {
        this.f19684c = onSelectSegmentListener;
    }

    public void setSelectedSegment(int i) {
        if (i == -1) {
            Timber.f23100a.mo3524e(new IllegalArgumentException());
            return;
        }
        int i2 = 0;
        while (i2 < this.f19682a.getChildCount()) {
            m4466b((TextView) ((FrameLayout) this.f19682a.getChildAt(i2)).getChildAt(0), i2 == i);
            i2++;
        }
        OnSelectSegmentListener onSelectSegmentListener = this.f19684c;
        if (onSelectSegmentListener != null) {
            onSelectSegmentListener.onSegmentSelected(i);
        }
        this.f19683b = i;
    }
}
